package com.gaoding.shared.dict.sdk.configuration;

import com.gaoding.grpc.client.annotation.GdGrpcClient;
import com.gaoding.shared.dict.rpc.service.DictTextContentServiceGrpc.DictTextContentServiceBlockingStub;
import com.gaoding.shared.dict.sdk.listen.Startup;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * @Description:
 * @Author: 西格 xige@gaoding.com
 * @date 2021-02-04 11:22
 */

@Configuration
@EnableConfigurationProperties({DictSdkProperties.class, SpringApplicationProperties.class})
public class DictSdkConfig {
    @GdGrpcClient
    private DictTextContentServiceBlockingStub dictTextContentServiceBlockingStub;

    @Bean
    public DictSdkProperties dictSdkProperties() {
        return new DictSdkProperties();
    }

    @Bean
    public SpringApplicationProperties springApplicationProperties() {
        return new SpringApplicationProperties();
    }

    @Bean
    public DictSdkComponentCollect dictSdkComponentCollect(DictSdkProperties dictSdkProperties, SpringApplicationProperties springApplicationProperties) {
        DictSdkComponentCollect dictSdkComponentCollect = new DictSdkComponentCollect();
        dictSdkComponentCollect.setDictTextContentServiceBlockingStub(dictTextContentServiceBlockingStub);
        dictSdkComponentCollect.setDictSdkProperties(dictSdkProperties);
        dictSdkComponentCollect.setSpringApplicationProperties(springApplicationProperties);
        return dictSdkComponentCollect;
    }

    @Bean("dict-startup")
    public Startup applicationStartup(DictSdkProperties dictSdkProperties) {
        return new Startup(dictSdkProperties.getEnable());
    }
}
